using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Rhizome.Contract;

namespace Rhizome.Internal
{
    internal static class Extension
    {

        public static void ForEach<T>(this IEnumerable<T> enumerable, Action<T> action)
        {
            foreach (var element in enumerable)
            {
                action(element);
            }
        }

		public static void ForEach(this IEnumerable enumerable, Action<object> action)
		{
			foreach (var element in enumerable)
			{
				action(element);
			}
		}

        public static void ForEachOfType<T>(this IEnumerable enumerable, Action<T> action)
        {
            foreach (var element in enumerable.OfType<T>())
            {
                action(element);
            }
        }

        public static string With(this String format, params object[] args)
        {
            return string.Format(format, args);
        }

		public static bool IsNullOrEmpty(this string s)
		{
			return string.IsNullOrEmpty(s);
		}

        public static bool IsMissing(this string s)
        {
            return string.IsNullOrEmpty(s) || string.IsNullOrEmpty(s.Trim());
        }

        public static string Join(this string[] values, string separator)
        {
            return string.Join(separator, values);
        }
    }
}